import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
var _excluded = ["tenantId"],
    _excluded2 = ["employeeList"],
    _excluded3 = ["employeeList"];

/**
 * service 员工维护与管理
 * @date: 2018-6-19


 */
import request from 'utils/request';
import { parseParameters } from 'utils/utils';
import { CPAAS_PLATFORM } from 'utils/config'; // const CPAAS_PLATFORM = `/cpfm-16353`;

/**
 * 请求API前缀
 * @type {string}
 */

var prefix = "".concat(CPAAS_PLATFORM, "/v1");
/**
 * 获取岗位信息
 * @async
 * @function searchPositionInfo
 * @param {object} params - 请求参数
 * @param {!number} params.tenantId - 租户Id
 * @param {!number} params.positionId - 岗位Id
 * @returns {object} fetch Promise
 */

export function searchPositionInfo(_x) {
  return _searchPositionInfo.apply(this, arguments);
}
/**
 * 获取岗位可添加员工信息列表
 * @async
 * @function searchAddibleStaff
 * @param {object} params - 请求参数
 * @param {!number} params.tenantId - 租户Id
 * @param {!number} params.positionId - 岗位Id
 * @param {!number} params.unitId - 部门Id
 * @param {!number} [params.page = {}] - 页码
 * @returns {object} fetch Promise
 */

function _searchPositionInfo() {
  _searchPositionInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request("".concat(prefix, "/").concat(params.tenantId, "/companies/units/positions/").concat(params.positionId), {
              method: 'GET' // body: params,

            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _searchPositionInfo.apply(this, arguments);
}

export function searchAddibleStaff(_x2) {
  return _searchAddibleStaff.apply(this, arguments);
}
/**
 * 获取岗位已维护员工信息列表
 * @async
 * @function searchAddedStaff
 * @param {object} params - 请求参数
 * @param {!number} params.tenantId - 租户Id
 * @param {!number} params.positionId - 岗位Id
 * @param {!number} params.unitId - 部门Id
 * @param {!object} [params.page = {}] - 分页参数
 * @returns {object} fetch Promise
 */

function _searchAddibleStaff() {
  _searchAddibleStaff = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    var tenantId, otherParams, param;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            tenantId = params.tenantId, otherParams = _objectWithoutProperties(params, _excluded);
            param = parseParameters(otherParams);
            return _context2.abrupt("return", request("".concat(prefix, "/").concat(tenantId, "/employee-assigns/not-in-position"), {
              method: 'GET',
              query: _objectSpread(_objectSpread({}, param), {}, {
                tenantId: tenantId
              })
            }));

          case 3:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _searchAddibleStaff.apply(this, arguments);
}

export function searchAddedStaff(_x3) {
  return _searchAddedStaff.apply(this, arguments);
}
/**
 * 岗位移除员工
 * @async
 * @function deleteStaff
 * @param {object} params - 请求参数
 * @param {!number} params.tenantId - 租户Id
 * @param {!number} params.positionId - 岗位Id
 * @param {!number} params.unit - 部门Id
 * @param {!array} params.employeeIdList - 员工id列表
 * @returns {object} fetch Promise
 */

function _searchAddedStaff() {
  _searchAddedStaff = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            param = parseParameters(params);
            return _context3.abrupt("return", request("".concat(prefix, "/").concat(param.tenantId, "/employee-assigns/in-position"), {
              method: 'GET',
              query: param
            }));

          case 2:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _searchAddedStaff.apply(this, arguments);
}

export function deleteStaff(_x4) {
  return _deleteStaff.apply(this, arguments);
}
/**
 * 岗位添加员工
 * @async
 * @function addStaff
 * @param {object} params - 请求参数
 * @param {!number} params.tenantId - 租户Id
 * @param {!number} params.positionId - 岗位Id
 * @param {!number} params.unit - 部门Id
 * @param {!array} params.employeeIdList - 员工id列表
 * @returns {object} fetch Promise
 */

function _deleteStaff() {
  _deleteStaff = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    var employeeList, query;
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            employeeList = params.employeeList, query = _objectWithoutProperties(params, _excluded2);
            return _context4.abrupt("return", request("".concat(prefix, "/").concat(params.tenantId, "/employee-assigns/position"), {
              method: 'DELETE',
              query: _objectSpread({}, query),
              body: employeeList
            }));

          case 2:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _deleteStaff.apply(this, arguments);
}

export function addStaff(_x5) {
  return _addStaff.apply(this, arguments);
}

function _addStaff() {
  _addStaff = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    var employeeList, query;
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            employeeList = params.employeeList, query = _objectWithoutProperties(params, _excluded3);
            return _context5.abrupt("return", request("".concat(prefix, "/").concat(params.tenantId, "/employee-assigns/position"), {
              method: 'POST',
              query: _objectSpread({}, query),
              body: employeeList
            }));

          case 2:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _addStaff.apply(this, arguments);
}